package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo11 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnecting()){
            connection.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);//可重复读
            connection.setAutoCommit(false);
            String sql="INSERT INTO user1(username,password,nickname,age) " +
                    "VALUES(?,?,?,?) ";
            PreparedStatement ps =connection.prepareStatement(sql);
            ps.setString(1,"艾斯");
            ps.setString(2,"123456");
            ps.setString(3,"光之锯人");
            ps.setInt(4,18);
            int num=ps.executeUpdate();
            System.out.println(num>0?"插入成功":"插入失败");
            connection.commit();
        } catch (Exception e) {

            e.printStackTrace();
        }
    }
}
